# PLAY WITH STRATEGY AND SHARE !
# PARAMETERS KNOWN IN INPUT :
# TSBITRATE
# PARAMETERS TO SET
# ------ Videos attributes ------
# VIDEORATE in Kbit/s
# VIDEOFPS in frame/s
# GOPSIZE in frame
# RESOLUTION Xsize x Ysize in pixels
# CODEC : h264 or h265

# AUDIORATE (32,48,64,128) in bit/s
# AUDIOCHANNELS (1,2) Mono or Stereo
# PCRPTS in ms
# 

# Very basic strategy



VIDEOFPS=25
CODEC=h265


# Comparaisons should be in that order !

AUDIORATE=64000
AUDIOCHANNELS=2
VIDEO_WIDTH=1920
VIDEO_HEIGHT=1080
VIDEORATE=$(echo "($TSBITRATE/1000)*85/100-10-$AUDIORATE/1000" | bc)
VIDEOFPS=25

if [ "$VIDEORATE" -lt 1200 ]; then
AUDIORATE=64000
AUDIOCHANNELS=2
			    GOPSIZE=50
				VIDEOFPS=25
				VIDEO_WIDTH=1280
				VIDEO_HEIGHT=720
				VIDEORATE=$(echo "($TSBITRATE/1000)*80/100-10-$AUDIORATE/1000" | bc)
fi

if [ "$VIDEORATE" -lt 400 ]; then
AUDIORATE=32000
AUDIOCHANNELS=2
	GOPSIZE=50
	VIDEOFPS=25
		VIDEO_WIDTH=768
		VIDEO_HEIGHT=432
		VIDEORATE=$(echo "($TSBITRATE/1000)*75/100-10-$AUDIORATE/1000" | bc)
fi

if [[ "$VIDEORATE" -lt 250 ]]; then
AUDIORATE=32000
AUDIOCHANNELS=1
	GOPSIZE=30
	VIDEO_WIDTH=576
	VIDEO_HEIGHT=324
	VIDEOFPS=15
	VIDEORATE=$(echo "($TSBITRATE/1000)*75/100-10-$AUDIORATE/1000" | bc)
fi

if [[ "$VIDEORATE" -lt 200 ]]; then
AUDIORATE=32000
AUDIOCHANNELS=1
GOPSIZE=30
VIDEO_WIDTH=384
VIDEO_HEIGHT=216
VIDEOFPS=15
VIDEORATE=$(echo "($TSBITRATE/1000)*65/100-10-$AUDIORATE/1000" | bc)
fi

if [[ "$VIDEORATE" -lt 100 ]]; then
AUDIORATE=32000
AUDIOCHANNELS=1
GOPSIZE=20
VIDEO_WIDTH=384
VIDEO_HEIGHT=216
VIDEOFPS=10
VIDEORATE=64
fi

RESOLUTION="$VIDEO_WIDTH"x"$VIDEO_HEIGHT"
echo VBitrae $VIDEORATE Reso $RESOLUTION at $VIDEOFPS